/*********************************************************************************
 * 文件名称: aliyun_iot_platform_pthread.c
 * 作       者:
 * 版       本:
 * 日       期: 2016-05-30
 * 描       述:
 * 其       它:
 * 历       史:
 **********************************************************************************/
#include "aliyun_iot_common_datatype.h"
#include "aliyun_iot_common_error.h"
#include "aliyun_iot_common_log.h"
#include "aliyun_iot_platform_pthread.h"


INT32 aliyun_iot_mutex_init(ALIYUN_IOT_MUTEX_S *mutex)
{
    return (INT32)pthread_mutex_init(&(mutex->lock),NULL);
}

INT32 aliyun_iot_mutex_lock(ALIYUN_IOT_MUTEX_S *mutex)
{
    return (INT32)pthread_mutex_lock(&mutex->lock);
}

INT32 aliyun_iot_mutex_unlock(ALIYUN_IOT_MUTEX_S *mutex)
{
    return (INT32)pthread_mutex_unlock(&mutex->lock);
}

INT32 aliyun_iot_mutex_destory(ALIYUN_IOT_MUTEX_S *mutex)
{
    return (INT32)pthread_mutex_destroy(&mutex->lock);
}

INT32 aliyun_iot_pthread_create(ALIYUN_IOT_PTHREAD_S* handle,VOID*(*func)(VOID*),VOID *arg,ALIYUN_IOT_PTHREAD_PARAM_S*param)
{
    pthread_attr_t attr;
    pthread_attr_init(&attr);
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);

    return pthread_create(&handle->threadID,&attr,func,arg);
}

INT32 aliyun_iot_pthread_cancel(ALIYUN_IOT_PTHREAD_S*threadID)
{
    if(threadID->threadID != 0)
    {
        return pthread_cancel(threadID->threadID);
    }

    return 0;
}

INT32 aliyun_iot_pthread_taskdelay(int MsToDelay)
{
    return usleep(MsToDelay*1000);
}



